home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / HTOCRK81.ZIP / HTOCRK81.TXT < prev    next >
Text File  |  1996-05-20  |  19KB  |  624 lines

  1.                      HOW TO CRACK, by +ORC, A TUTORIAL
  2.  
  3. ---------------------------------------------------------------------------
  4.  
  5.                Lesson 8.1: How to crack Windows, an approach
  6.  
  7. ---------------------------------------------------------------------------
  8.  
  9.                                 [WINPGP.EXE]
  10.  
  11.                    --------------------------------------
  12.  
  13. --------------------------------------------------------
  14.  
  15.      SPECIAL NOTE: Please excuse the somehow "unshaven"
  16.  
  17.      character of the windows lessons... I'm cracking the
  18.  
  19.      newest Windows '95 applications right now, therefore
  20.  
  21.      at times I had to add "on the fly" some corrections to
  22.  
  23.      the older Windows 3.1 and Windows NT findings.
  24.  
  25.                 "homines, dum docent, discunt".
  26.  
  27. ---------------------------------------------------------
  28.  
  29. ->   1st THING TO REMEMBER
  30.  
  31. The NE format does give every windows executable the equivalent
  32.  
  33. of a debug symbol table: A CRACKER BLISS!
  34.  
  35. ->   UNDOCUMENTED DEBUGGING
  36.  
  37. One of the many feature of Windows based on undocumented
  38.  
  39. foundations is the "ability to debug".
  40.  
  41. A word about undocumented functions in the MS-Operating Systems:
  42.  
  43. Microsoft manipulates its rule and domination of the operating
  44.  
  45. systems in use to day (MS-DOS, Windows, Windows '95) with two
  46.  
  47. main wicked aims:
  48.  
  49. 1)   getting the concurrence completely bankrupt (that's the
  50.  
  51.      scope of all the using of undocumented functions and
  52.  
  53.      CHANGING them as soon as the concurrence uses them). The
  54.  
  55.      battle against Borland was fought in this way.
  56.  
  57. 2)   getting all future "programmers" to use windows as a "black
  58.  
  59.      box" that only Microsoft engineers (if ever) can master, so
  60.  
  61.      that everybody will have to sip the ill-cooked abominations
  62.  
  63.      from Microsoft without ever having a chance to alter or
  64.  
  65.      ameliorate them.
  66.  
  67. Strange as it may seem, only the sublime cracker community fights
  68.  
  69. against these intolerable plans. All stupid governments and
  70.  
  71. lobbies -on the contrary- hide behind the fig-leaf of the
  72.  
  73. "market" "freedom" in order to ALLOW such heinous developments
  74.  
  75. (I'm speaking as if they were capable to opposing them even if
  76.  
  77. they wanted, which they do not. Be assured, they couldn't anyway,
  78.  
  79. "Governments" are deliberately MADE to serve Gates and all the
  80.  
  81. remaining suckers, and lobbies are the shield of feudalism. You
  82.  
  83. can forget "democracy", the only rule existing is a malevolent
  84.  
  85. oligarchy based on money, personal connections, defect of
  86.  
  87. culture, lack of knowledge and dictatorship of bad taste through
  88.  
  89. television in order to keep the slaves tamed... enough now...)
  90.  
  91. The windows situation is particularly reminiscent of the older
  92.  
  93. situation in DOS, where for years the key "load but don't
  94.  
  95. execute" function, used by debuggers, such as [DEBUG], [SYMDEB]
  96.  
  97. and [CODEVIEW], was "reserved" by Microsoft.
  98.  
  99.      The windows debugging library, WINDEBUG.DLL, a number of
  100.  
  101. undocumented functions and even the interface it provides are
  102.  
  103. undocumented! The WinDebug() function is used by all available
  104.  
  105. windows debuggers, including [CVW] (CodeView for Windows), [TDW]
  106.  
  107. (TurboDebugger for Windows), [Multiscope] and [Quick C for
  108.  
  109. Windows] (the last two are GUI, not text debuggers. The use of
  110.  
  111. WinDebug() doesn't show up in MAPWIN output 'coz debuggers link
  112.  
  113. to it at run-time via the amazing GetProcAddress() function.
  114.  
  115.      WinDebug() is a hacked 32-bit version, for the old Windows
  116.  
  117. 3.0, of the poorly documented DOSPTrace() function from OS/2 1.x
  118.  
  119. (study these older Operating Systems! Studying the past you'll
  120.  
  121. understand EVERYTHING! Sometime I think that the only way to hack
  122.  
  123. and crack correctly is to be more a software historian than a
  124.  
  125. programmer... fac sapias et liber eris!). DOSPTrace is, in turn,
  126.  
  127. based on the ptrace() function in Unix.
  128.  
  129.      Like DosPTrace(), WinDebug() takes commands such as Go,
  130.  
  131. Single-Step, Write&Read Registers, Write&Read Memory. It returns
  132.  
  133. to its caller either when the command completes or when a
  134.  
  135. breakpoint occurs (or a DLL load). These commands and
  136.  
  137. notifications appear in a large structure whose address is passed
  138.  
  139. in WinDebug().
  140.  
  141.      WinDebug() was renamed CVWIN.DLL (and TDWIN.DLL) for Windows
  142.  
  143. 3.1., all crackers should study it and get the maximum possible
  144.  
  145. documentation about it. As you will see in the following, it is
  146.  
  147. worth to study also TOOLHELP.DLL (what Microsoft would like you
  148.  
  149. to fiddle with) and INT_41h (the real debugging interface).
  150.  
  151. Interrupt handling under Windows
  152.  
  153.      Interrupt handling under Windows can be tricky: you need to
  154.  
  155. use Toolhelp (a rather scaring lobotomy for your programs) or to
  156.  
  157. have special code for Standard vs. Enhanced modes, because the
  158.  
  159. information on the stack of an interrupt or exception handler
  160.  
  161. differs between the two windows modes. In addition, some handlers
  162.  
  163. would be installed using INT_21h, while others are set up using
  164.  
  165. DPMI services. Toolhelp has quite a bit of internal code that
  166.  
  167. "cooks" the interrupts and sends them to you in an easily
  168.  
  169. digestible form.
  170.  
  171.      Remember that Windows uses GP faults as a "hacker" method
  172.  
  173. of doing ring transitions that are not allowed with legal 80x86
  174.  
  175. instructions: the virtual memory system of Enhanced mode is
  176.  
  177. implemented via the page fault.
  178.  
  179. Some tools for cracking windows (-> see lesson 9)
  180.  
  181. -----------------          DEBUGGERS
  182.  
  183. CVW and TDW         (you have to know the function's
  184.  
  185.                     segment:offset address beforehand in order
  186.  
  187.                     to crack a function)
  188.  
  189. WCB                 [Windows Codeback] by Leslie Pusztai (it's
  190.  
  191.                     a really cool tool!)
  192.  
  193. WDEB386             Microsoft's WDEB386 (clumsy, and requires a
  194.  
  195.                     second monitor)
  196.  
  197. Soft-Ice/Windows    best (BY FAR!) windows debugger! NuMega is
  198.  
  199.                     so good I am at times really sorry to crack
  200.  
  201.                     their products! [WINICE] is the single,
  202.  
  203.                     absolutely essential debugger and snooping
  204.  
  205.                     utility for windows crackers. Get it!
  206.  
  207. -----------------   POST MORTEM INSPECTORS
  208.  
  209. CORONER, etc.            (a lot of shareware)
  210.  
  211. MS-DrWatson              Old and clumsy
  212.  
  213. Borland's Winspector     THE BEST! It has the BUILDSYM utility
  214.  
  215.                          that allows the creation of a debug
  216.  
  217.                          .SYM file from an .EXE without debug
  218.  
  219.                          information.
  220.  
  221. -----------------         INSPECTORS
  222.  
  223. MS-Spy                   Old
  224.  
  225. Borland's WinSight       (Best one, select "Other")
  226.  
  227. MicroQuill's Windows DeMystifiers (from Jeff Richter):
  228.  
  229.      VOYEUR (hold SHIFT picking Message Selection), COLONEL,
  230.  
  231.      MECHANIC and ECOLOGIST
  232.  
  233. -----------------          SNOOPERS
  234.  
  235. [INFSPY.EXE], 231.424 bytes, version 2.05 28/8/1994 by Dean
  236.  
  237. Software Design, may be the more complete one.
  238.  
  239. [SUPERSPY.EXE], 24.576 bytes, 10,6,1994, quite handy for quick
  240.  
  241. informations.
  242.  
  243. [WINVIEW.EXE], 30.832 bytes, Version 3.00 by Scott McCraw, MS(c)
  244.  
  245. 1990-1992, this is the old MS-Spy, distributed by MS
  246.  
  247. [TPWSPY.EXE], 9.472 bytes, quite primitive, but you get the
  248.  
  249. pascal source code with it.
  250.  
  251. ->   INSIDE A WINDOWS '95 DEBUGGER
  252.  
  253.      You can debug a program at the assembly-language level
  254.  
  255. without any debugging information. The DOS [DEBUG] program does
  256.  
  257. that, allowing breakpoints and single-stepping, all of which
  258.  
  259. implies that the hardware must be cooperating. Back in the time
  260.  
  261. of the 4-MHz Z-80s, you used a debugger that plugged interrupt
  262.  
  263. op codes into the instruction stream to generate breakpoints.
  264.  
  265.      Nothing has changed. That's how you debug a program on a
  266.  
  267. 80586 (=Pentium). The x86 architecture includes software
  268.  
  269. interrupts. The 1-byte op code xCC is the INT_03 instruction,
  270.  
  271. reserved for debuggers. You can put the INT_03 op code in place
  272.  
  273. of the program instruction op code where the break is to occur
  274.  
  275. and replace the original op code at the time of the interrupt.
  276.  
  277. In the 80386 and later, you can set a register flag that tells
  278.  
  279. the processor to generate a not-intrusive INT_01 instruction for
  280.  
  281. every machine instruction executed. That device supports single
  282.  
  283. stepping.
  284.  
  285.      The Win32SDK (Windows '95 software developer's kit) includes
  286.  
  287. functions that allow one program to launch another program and
  288.  
  289. debug it. The SDK's debug API takes care of how the interrupts
  290.  
  291. and interrupt vectors get managed. The logical consequence of
  292.  
  293. such an approach is that fewer and fewer people will be able to
  294.  
  295. know what's going on inside an application. The bulk of the
  296.  
  297. programmers -in few years time- will not be able any more to
  298.  
  299. reverse engineer an application, unless the few that will still
  300.  
  301. understand assembler-language do offer them the tools to do it.
  302.  
  303. Microsoft -it is evident- would like the programmers to use a
  304.  
  305. "black box" approach to programming, writing nice little "hallo
  306.  
  307. world" application and leaving to the engineers in Microsoft
  308.  
  309. alone the capacity to push forward (and sell) real programs that
  310.  
  311. are not toy application.
  312.  
  313.      The Win32 documentation seems vast, almost luxurious, until
  314.  
  315. you begin serious work and you discover its shortcomings, like
  316.  
  317. the fact that extended error codes are not documented, and
  318.  
  319. numerous APIs are documented either incorrectly or so poorly that
  320.  
  321. you must burn precious time testing them. What we definitely need
  322.  
  323. is to find some secret fellows inside Microsoft (like good old
  324.  
  325. Prometeus) that smuggles to the outside the real documentation
  326.  
  327. that the Microsoft engineers have reserved for themselves. If you
  328.  
  329. are reading this and do work for Microsoft, consider the
  330.  
  331. possibility of double-crossing your masters for the sake of
  332.  
  333. humanity and smuggle us the secret information.
  334.  
  335.      In windows '95 a debugger program launches a program to be
  336.  
  337. debugged by calling the _CreateProcess function, specifying in
  338.  
  339. an argument that the program is to be debugged. Then the debugger
  340.  
  341. program enters a loop to run the program. At the top of the loop
  342.  
  343. the debugger calls _WaitForDebugEvent.
  344.  
  345.      Each time _WaitForDebugEvent returns it sets indicators that
  346.  
  347. tell about the vent that suspended the program being debugged.
  348.  
  349. This is where the debugger traps breakpoints and single-step
  350.  
  351. exceptions. _WaitForDebugEvent fills in an event structure that
  352.  
  353. contains among other things the address that was interrupted end
  354.  
  355. the event that caused the interrupt.
  356.  
  357.      The debugger calls _GetThreadContext to get the running
  358.  
  359. context of the debugged program, including the contents of the
  360.  
  361. registers. The debugger can, as the result of cracker
  362.  
  363. interaction, modify these values and the contents of the debugged
  364.  
  365. program's memory.
  366.  
  367.      The debugger sets breakpoints by saving the op code at the
  368.  
  369. instruction to be intercepted and putting the INT_03 op code at
  370.  
  371. its place, it's always the same old marmalade. When the
  372.  
  373. breakpoint occurs, the debugger replaces the original op code in
  374.  
  375. the program's instruction memory, and decrements the interrupted
  376.  
  377. program counter in the saved context so that execution resumes
  378.  
  379. at the instruction that was broken.
  380.  
  381.      To single-step a program, the debugger sets a bit in the
  382.  
  383. context's flags register that tells the processor to generate an
  384.  
  385. INT_01 for every instruction cycle. When that interrupt occurs,
  386.  
  387. the debugger checks to see if the interrupted address is at a new
  388.  
  389. source-code line number. If not, the debugger continues
  390.  
  391. execution. Otherwise, the debugger displays the new line in the
  392.  
  393. IDE and waits for the cracker to take an action that resumes the
  394.  
  395. program.
  396.  
  397.      While the debugged program is suspended, the debugger
  398.  
  399. interacts with the cracker and provides full access to the
  400.  
  401. debugged program's context and memory. This access permits the
  402.  
  403. cracker to examine and modify part of the code.
  404.  
  405.      To resume the debugged program, the debugger resets the
  406.  
  407. program's context by calling _SetThreadContext and calls
  408.  
  409. _ContinueDebugEvent. Then, the debugger returns to the top of the
  410.  
  411. loop to call _WaitForDebugEvent again.
  412.  
  413.      To extract debug information from a Win32 executable file,
  414.  
  415. you must understand the format of that file (best thing to do,
  416.  
  417. to practice yourself, would be to reverse engineer small
  418.  
  419. programs). The executable file has two sections not found in
  420.  
  421. other executable files: ".stab" and ".stabstr". How nice that
  422.  
  423. they used names that suggest their purpose (nomen est omen).
  424.  
  425. You'll find them inside a table of fixed-length entries that
  426.  
  427. include entries for .text, .bss, .data and .idata. Inside these
  428.  
  429. sections the compilers put different parts of a program.
  430.  
  431.      There are several different formats for encoding debug
  432.  
  433. information in an executable file. Borland's Turbo Debugger  one
  434.  
  435. format. Microsoft's CodeView  another. The gnu-win32 port from
  436.  
  437. Cygnus the stab format, an acronym meaning "symbol table",
  438.  
  439. although the table contains much more than just symbol
  440.  
  441. information.
  442.  
  443.      The .stab section in a portable executable file is a table
  444.  
  445. of fixed-length entries that represent debugging information in
  446.  
  447. the stab format. The .stabstr section contains variable-length,
  448.  
  449. null terminated strings into which the .stab table entries point.
  450.  
  451.      The documentation for the stab format is available in text
  452.  
  453. format on the Cygnus ftp site (ftp.cygnus.com//pub/gnu-win32).
  454.  
  455.      Stabs contain, in a most cryptic format, the names and
  456.  
  457. characteristics of all intrinsic and user-defined types, the
  458.  
  459. memory address of every symbol in external memory and on the
  460.  
  461. stack, the program counter address of every function, the program
  462.  
  463. counter address where every brace-surrounded statement block
  464.  
  465. starts and ends, the memory address of line numbers within
  466.  
  467. source-code files, and anything else that a debugger needs. The
  468.  
  469. format is complex and cryptic because it is intended to support
  470.  
  471. any source-code language. It is the responsibility of a debugger
  472.  
  473. program to translate the stab entries into something meaningful
  474.  
  475. to the debugger in the language being debugged.
  476.  
  477.      Windows '95 invokes dozens of INT_21 services from 32-bit
  478.  
  479. code, including KERNEL32.DLL and possess Krn32Mutex, which
  480.  
  481. apparently controls access to certain parts of the kernel. Some
  482.  
  483. of the functions in KERNEL32 can be blocked by the Win16Mutex,
  484.  
  485. even though Microsoft says this isn't the case.
  486.  
  487. SO, I WANNA CRACK, WHAT SHOULD I DO?
  488.  
  489.      I'll show you a simple windows crack, so easy it can be done
  490.  
  491. without WINICE: let's take [WINPGP4.1.] (front-end for PGPing in
  492.  
  493. windows, by Geib - I must thank "Q" for the idea to work on this
  494.  
  495. crack).
  496.  
  497.      Using WCB you'll find out quickly that the "CONGRATULATIONS
  498.  
  499. your registration number is OK" and the "SORRY, your registration
  500.  
  501. number is not correct" data blocks are at the block starting at
  502.  
  503. 36.38B8 (respectively at 36.38D5 and 36.3937), that relocs to
  504.  
  505. 13.081B.
  506.  
  507.      Looking at 13.0000 and following code, you'll find a push
  508.  
  509. 38D5 (68D538) and a push 3937 (683739) at 13.064D and 13.06AE.
  510.  
  511.      The road to the crack is now open, you just need to find and
  512.  
  513. "fool" the calling routines. You'll learn the exact procedures
  514.  
  515. for this kind of WINcracks in part 2 and 3 of -> Lesson 8. Let's
  516.  
  517. now have a look at the protection scheme (disassembly from WCB):
  518.  
  519. ...
  520.  
  521. 13.0E88   660FBF46F8     movsx     eax, word ptr [bp-08]
  522.  
  523. 13.0E8D   668946F4       mov       [bp-0C], eax
  524.  
  525. 13.0E91   668B46F4       mov       eax, [bp-0C]
  526.  
  527. 13.0E95   6669C00A000300 imul      eax, 0003000A
  528.  
  529. 13.0E9C   668946F0       mov       [bp-10], eax
  530.  
  531. 13.0EA0   668B4606       mov       eax, [bp+06]
  532.  
  533. 13.0EA4   663B46F0       cmp       eax, [bp-10]
  534.  
  535. 13.0EA8   7505           jne       0EAF      <- beggar_off
  536.  
  537. 13.0EAA   B80100         mov       ax, 0001  <- flag 1 = "Right!"
  538.  
  539. 13.0EAD   EB04           jmp       0EB3      <- and go on
  540.  
  541. beggar_off:
  542.  
  543. 13.0EAF   33C0           xor       ax,ax     <- flag 0 = "Nope!"
  544.  
  545. 13.0EB1   EB00           jmp       0EB3      <- and go on
  546.  
  547.      I want you to have a good look at this protection scheme.
  548.  
  549. IT'S THE SAME OLD SOUP! You do remember lesson 3 and the
  550.  
  551. protection schemes of the old DOS stupid games of the '80s, don't
  552.  
  553. you? IT'S THE SAME OLD SOUP! In this "up-to-date" "new" windows
  554.  
  555. application, in WINPGP version 4.1 of 1995/1996, exactly the same
  556.  
  557. kind of protection is used to "conceal" the password!
  558.  
  559. A)   compare user input with memory echo
  560.  
  561. B)   beggar off if not equal with AX=0
  562.  
  563. C)   go on if equal with AX=1... how boring!
  564.  
  565.      Besides, look at all the mov eax, and  eax, moves preceding
  566.  
  567. the compare! That's a typical pattern for these "number_password"
  568.  
  569. protections! I wrote (years ago) a little crack utility that
  570.  
  571. searches for code blocks with a "66" as first instruction_byte
  572.  
  573. repeating in four or more consecutive instructions and it still
  574.  
  575. allows me to crack more than half of these windows password smuts
  576.  
  577. in less than three seconds flat. The IMUL instruction creates the
  578.  
  579. "magic" number, and if you give a closer look at the mathematical
  580.  
  581. part of the "conceal" routine, it could help you to crack
  582.  
  583. analogous schemes used in order to protect the "Instant access"
  584.  
  585. (c) & (tm) time_crippled software :=)
  586.  
  587.      Now you could crack the above code in 101 different ways,
  588.  
  589. the most elegant one would probably substitute je 0EAF (or jZ
  590.  
  591. 0EAF, that's the same) to the jne 0EAF at 13.0EA8. You just write
  592.  
  593. a 74 at the place of the 75, like you did for the cracks in
  594.  
  595. 1978... how boring: it's really the same old soup! (But you'll
  596.  
  597. see some new tricks in the next lessons).
  598.  
  599. Well, that's it for this lesson, reader. Not all lessons of my
  600.  
  601. tutorial are on the Web.
  602.  
  603.      You 'll obtain the missing lessons IF AND ONLY IF you mail
  604.  
  605. me back (via anon.penet.fi) with some tricks of the trade I may
  606.  
  607. not know that YOU discovered. Mostly I'll actually know them
  608.  
  609. already, but if they are really new you'll be given full credit,
  610.  
  611. and even if they are not, should I judge that you "rediscovered"
  612.  
  613. them with your work, or that you actually did good work on them,
  614.  
  615. I'll send you the remaining lessons nevertheless. Your
  616.  
  617. suggestions and critics on the whole crap I wrote are also
  618.  
  619. welcomed.
  620.  
  621.                                 E-mail +ORC
  622.  
  623.                          +ORC 526164@anon.penet.fi
  624.